package Exams.Zoom;

import java.util.Scanner;

class ListNode {
    long val;
    ListNode next;

    public ListNode(long val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class Q2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int root = 0;
        int n = sc.nextInt();
        System.out.println(n);
        int color[] = new int[n];
        ListNode[] Graph = new ListNode[n];
        for (int i = 0; i < n; i++) {
            Graph[i] = new ListNode(0, null);
        }
        sc.nextLine();
        String str = sc.nextLine();
        System.out.println(str);
        for (int i = 0; i < n; i++) {
            if (str.charAt(i) == 'R') {
                color[i] = 1;
            }
        }
        for (int i = 0; i < n - 1; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            insert(u, v, Graph);
        }
        int visited[] = new int[n];
        dfs(root, visited, 0, 0, color, Graph);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += Graph[i].val;
        }
        System.out.println(ans);
    }


    public static void insert(int u, int v, ListNode[] G) {
        ListNode vNode = new ListNode(v, G[u].next);
        G[u].next = vNode;
        ListNode uNode = new ListNode(u, G[v].next);
        G[v].next = uNode;
    }

    public static void dfs(int root, int[] visited, int red, int blue, int color[], ListNode[] G) {
        visited[root] = 1;
        if (color[root] == 1) red++;
        else blue++;
        G[root].val = Math.abs(red - blue);
        ListNode p = G[root].next;
        while (p != null) {
            if (visited[(int) p.val] != 1) {
                dfs((int) p.val, visited, red, blue, color, G);
            }
            p = p.next;
        }
        visited[root] = 0;
    }
}

